import { IResponse } from "@/pages/main/right/sub1/type"; 
import { getServiceGoodsNorms, getServiceGoodsType } from "@/service/goods";
import { action, makeAutoObservable, makeObservable, observable } from "mobx"

class Store {
  spinning = false
  constructor() {
    makeAutoObservable(this, {}, { autoBind: true })
    // makeObservable(this, {
    //   spinning: observable,
    //   setSpinning: action.bound,
    //   getGoodsNorms: action,
    //   getGoodsType: action
    // })
  }
  
  // @action.bound
  // 这里也可以使用箭头函数把this固定在函数体内
  setSpinning(flag: boolean) {
    this.spinning = flag
  }

  // 请求商品规格接口
  async getGoodsNorms(): Promise<IResponse | undefined> {
    const res = await getServiceGoodsNorms();
    if (res && res.code == 200) {
      return res;
    }
  }

  // 请求商品种类接口
  async getGoodsType(): Promise<IResponse | undefined> {
    const res: IResponse = await getServiceGoodsType();
    if (res && res.code == 200) {
      return res;
    }
  };
}

const store = new Store()
export default store